package com.llb666.shop.items.infrastructure.persistence;

import com.llb666.shop.items.domain.entity.Carousel;
import com.llb666.shop.items.domain.repository.CarouselRepository;
import com.llb666.shop.items.infrastructure.conver.CarouselCvt;
import com.llb666.shop.items.infrastructure.mapper.CarouselMapper;
import com.llb666.shop.items.infrastructure.po.CarouselPo;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

/**
 * 首页轮播图仓储层实现类.
 *
 * @author llb666
 */
@Repository
@RequiredArgsConstructor(onConstructor_ = {@Autowired})
public class CarouselRepositoryImpl implements CarouselRepository {

    private final CarouselMapper carouselMapper;

    /**
     * 查询轮播图.
     *
     * @param isShow 是否显示首页
     * @return 轮播图列表
     */
    @Override
    public List<Carousel> queryAll(Integer isShow) {
        Example example = new Example(CarouselPo.class);
        example.orderBy("sort").desc();
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("isShow", isShow);
        return CarouselCvt.INSTANCE.po2doList(carouselMapper.selectByExample(example));
    }

}
